package com.easyj.base.security;


import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
	 *简单的用户信息和权限，保存在session、cache 
*/

public class SimpleUser  implements UserDetails{
	 
	private static final long serialVersionUID = 1L;


	private Long id;
	
	//部们Id
	private Long departmentId;
	

	/**
	 * 中文姓名，真实姓名   
	 */
	private String name; 

    /**
     *   登录账号
     */
	private String loginName;
	
    private String username;
    
    private boolean locked;
    private boolean enable;
    private  List<GrantedAuthority> authorities;
    
    @JsonIgnore
	private String password;
    
    public SimpleUser(Long id,Long deptId,String name,String  username,String password,String duty,boolean enable,boolean locked) {
    	this.id=id;
    	this.username=username;
    	this.password=password;
    	this.enable=enable;
    	this.name=name;
    	this.departmentId=deptId;
    	this.locked=locked;
    }
    
   
	
	public SimpleUser(Long id,Long deptId,String name,String  username,String password,boolean enable,boolean locked,List<GrantedAuthority> authorities) {
    	this.id=id;
    	this.username=username;
    	this.name=name;
    	this.password=password;
    	this.enable=enable;
    	this.departmentId=deptId;
    	this.locked=locked;
    	this.authorities=authorities;
    }
	
	public SimpleUser(Long id,Long deptId,String name,String  username,String loginName,List<GrantedAuthority> authorities) {
    	this.id=id;
    	this.username=username;
    	this.loginName=loginName;
    	this.name=name;
    	this.password=null;
    	this.enable=true;
    	this.departmentId=deptId;
    	this.locked=false;
    	this.authorities=authorities;
    }
	
	
	public String getLoginName() {
			return loginName;
	}

    
    public void setAuthorities(List<GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}



	public Long getId() {
		return id;
	}
  
	public Long getDepartmentId() {
		return departmentId;
	}

	

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}


	@Override
	public String getPassword() {
		return password;
	}


	@Override
	public String getUsername() {
		return username;
	}


	@Override
	public boolean isAccountNonExpired() {
		return true;
	}


	@Override
	public boolean isAccountNonLocked() {
		return !locked;
	}


	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}


	@Override
	public boolean isEnabled() {
		return enable;
	}
    
	    
}
